package edu.tfg.feed;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;

import edu.tfg.cliente.Cliente;

public class FeedDAOHibernate implements FeedDAO{
	
	private Session sessao;
	@Override
	public void salvar(Feed feed) {
		this.sessao.save(feed);			
	}
	
	public Session getSessao() {
		return sessao;
	}
	
	public void setSessao(Session sessao) {
		this.sessao = sessao;
	}

	@Override
	public List<Feed> listar() {
		Criteria lista = sessao.createCriteria(Feed.class);
		return lista.list();
	}

	@Override
	public void excluir(Feed feed) {
		this.sessao.delete(feed);
	}

	@Override
	public Feed pesquisar(String string) {
		Query consultaTitulo = this.sessao
				.createQuery("from Feed f where f.titulo like :titulo");
		consultaTitulo.setString("titulo", "%" + string + "%");
		return (Feed) consultaTitulo.uniqueResult();
	}

	@Override
	public void alterar(Feed feed) {
		this.sessao.update(feed);
		
	}

	@Override
	public Feed pesquisarPorCodigo(Integer codigoString) {
		// TODO Auto-generated method stub
		return null;
	}

}
